package tk.mybatis.springboot;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import tk.mybatis.springboot.constants.RequestLimit;
import tk.mybatis.springboot.listener.ContextListener;
import tk.mybatis.springboot.model.Message;
import tk.mybatis.springboot.ping.service.PingService;
import tk.mybatis.springboot.service.WexinInsuranceService;

@Controller
@EnableWebMvc
@EnableCaching
@SpringBootApplication
@MapperScan(basePackages = "tk.mybatis.springboot.mapper")
public class Application extends WebMvcConfigurerAdapter {
	@Autowired
	PingService pingService;
	
	@Autowired
	private WexinInsuranceService wexinInsuranceService;
    public static void main(String[] args) {
    	SpringApplication springApplication = new SpringApplication(Application.class);
    	springApplication.addListeners(new ContextListener());
    	springApplication.run(args);
    }

    @RequestMapping(value = "/", method = RequestMethod.GET)
    @ResponseBody
    public void home(HttpServletRequest request, HttpServletResponse response) throws Exception {
    	response.sendRedirect("https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxd42c9d6302a27cf9&redirect_uri=http%3a%2f%2fqa.mobile.ydche.com%2fweixin%2fuser&response_type=code&scope=snsapi_userinfo&state=zhangli#wechat_redirect");
    }
    
    @RequestMapping(value = "/clear", method = RequestMethod.GET)
    @ResponseBody
    public Message clear(HttpServletRequest request, HttpServletResponse response) throws Exception {
    	return pingService.pay("30588246", request, 2, "www.baidu.com",7);
    }
    
    @RequestMapping(value = "/text", method = RequestMethod.GET)
    @ResponseBody
    @RequestLimit(limit=10,time=3600000)
    public void text(HttpServletRequest request, HttpServletResponse response) throws Exception {
    	System.out.println("666");
    }
}
